<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8" />
    <title>Toast - Buttons</title>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
    />
    <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
    <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
    <script src="../../../../../scripts/testing/scripts.js"></script>
    <script nomodule src="../../../../../dist/ionic/ionic.js"></script>
    <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
  </head>
  <script type="module">
    import { toastController } from '../../../../dist/ionic/index.esm.js';
    window.toastController = toastController;
  </script>
  <body>
    <ion-app>
      <ion-header>
        <ion-toolbar>
          <ion-title>Toast - Buttons</ion-title>
        </ion-toolbar>
      </ion-header>

      <ion-content class="ion-padding" id="content">
        <!-- New way using array of buttons -->
        <button id="closeArray" class="expand" onclick="presentCloseArrayToast()">Close Button Array</button>

        <button id="twoButtons" class="expand" onclick="presentToastWithTwoButtons()">Two Buttons</button>

        <button id="multipleButtons" class="expand" onclick="presentToastWithMultipleButtons()">
          Multiple Buttons
        </button>

        <button id="longButton" class="expand" onclick="presentToastWithLongButton()">Really Long Button</button>
      </ion-content>
    </ion-app>

    <script>
      window.addEventListener('ionToastDidDismiss', function (e) {
        console.log('didDismiss', e);
      });
      window.addEventListener('ionToastWillDismiss', function (e) {
        console.log('willDismiss', e);
      });

      async function presentCloseArrayToast() {
        const opts = {
          message: 'Are you sure you want to delete this?',
          buttons: [
            {
              text: 'Delete',
              role: 'cancel',
            },
          ],
        };

        return await presentToastWithOptions(opts);
      }

      async function presentToastWithTwoButtons() {
        const opts = {
          message: "Can't send photo. Retry in 5 seconds.",
          buttons: [
            {
              text: 'retry',
              handler: () => {
                console.log('retry button clicked!');
                return false;
              },
            },
            {
              icon: 'close',
              role: 'cancel',
              handler: () => {
                console.log('close button clicked!');
              },
            },
          ],
        };

        return await presentToastWithOptions(opts);
      }

      async function presentToastWithMultipleButtons() {
        const opts = {
          message: 'Error.',
          buttons: [
            {
              text: 'undo',
              side: 'start',
              handler: () => {
                console.log('undo button clicked!');
              },
            },
            {
              text: 'retry',
              handler: () => {
                console.log('retry button clicked!');
                return false;
              },
            },
            {
              icon: 'close',
              role: 'cancel',
              handler: () => {
                console.log('close button clicked!');
              },
            },
          ],
        };

        return await presentToastWithOptions(opts);
      }

      async function presentToastWithLongButton() {
        const opts = {
          message: 'This item already has the label "travel". You can add a new label.',
          buttons: [
            {
              text: 'Add a New Label',
              handler: () => {
                console.log('long button clicked!');
              },
            },
          ],
        };

        return await presentToastWithOptions(opts);
      }

      async function presentToastWithOptions(opts) {
        const toast = await toastController.create(opts);
        await toast.present();
      }
    </script>
  </body>
</html>
